<?php
$action = $_REQUEST['action'];
$cote= $_REQUEST['cote'];
$nom = $_REQUEST['nom'];
$lien = $_REQUEST['lien'];
$categorie = $_REQUEST['categorie'];
if (!$action || !$cote || !$nom || !$lien || !$categorie){
	echo 'Erreur de transfert' . $action . $cote . $nom . $lien . $categorie;
}
else{
	include 'infobd.php';
        include 'accent.php';

        $nom = str_replace($normalaccent, $codeaccent, $nom);
        $categorie = str_replace($normalaccent, $codeaccent, $categorie);
        if (!strstr($lien, 'http')){
                $lien = "http://" . $lien;
        }
	
	$con = mysql_connect($serv,$user,$passw);
	if (!$con)
  	{
  		die('Could not connect: ' . mysql_error());
  	}

	mysql_select_db($db, $con);
	
	$requete = "";
	if($action == "add"){
		$requete = sprintf("insert into site (nom, lien, categorie) values('%s','%s', '%s')",
    		mysql_real_escape_string($nom),
    		mysql_real_escape_string($lien),
			mysql_real_escape_string($categorie));
	}
	if($action == "del"){
		$requete = sprintf("delete from site where cote = '%s'",
    		mysql_real_escape_string($cote));
	}
	if($action == "mod"){
		$requete = sprintf("update site set nom = '%s', lien = '%s', categorie = '%s' where cote = " . $cote, mysql_real_escape_string($nom), mysql_real_escape_string($lien),
			mysql_real_escape_string($categorie));
	}

	if ($requete != ""){
		if (!mysql_query($requete,$con))
		{
			die('Error: ' . mysql_error());
		}
	}
	mysql_close($con);
        include 'selectadminlien.php';
}
?>